<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>录入入库单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form" action=""  id="example" lay-filter="example">
                        <!--类型-->

                        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a>
              <cite>录入入库单/Enter receipt doc</cite></a>
          </span>
                            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
                               onclick="location.reload()" title="刷新">
                                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
                        </div>
                        <br>

                        <div class="layui-form-item">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-inline">
                                <select name="drType" lay-filter="drType">
                                    <option value="">请选择</option>
                                    <option value="10">袋装颗粒</option>
                                    <option value="11">颗粒</option>
                                    <option value="12">饮片</option>
                                </select>
                            </div>

                            <!--药品名称-->
                            <div class="layui-inline">
                                <label class="layui-form-label">药品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="drName" id="test2" lay-verify="required" placeholder=""
                                           lay-reqtext="药品名称是必填项，不能为空！"  autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <!--数量-->
                            <div class="layui-inline">
                                <label class="layui-form-label">数量</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="wareAmount" id="wareAmount" lay-verify="required" placeholder=""
                                           lay-reqtext="数量是必填项，不能为空！"  autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <!--仓库单位-->
                            <div class="layui-inline">
                                <label class="layui-form-label">仓库单位:</label>
                                <div class="layui-input-inline">
                                    <select name="drUnit" lay-filter="drUnit">
                                        <option value="">请选择</option>
                                        <option value="34">盒</option>
                                        <option value="35">袋</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">规格</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="drSpecs" id="test5" lay-verify="" placeholder=""
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">进货单价</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="warePrice" id="warePrice" lay-verify="required" placeholder=""
                                           lay-reqtext="进货单价是必填项，不能为空！"  autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">进货总价</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="warePriceTotal" id="warePriceTotal" lay-verify="" readonly="readonly" placeholder="数量X进货单价"
                                           lay-reqtext="进货总价是必填项，不能为空！"  autocomplete="off" class="layui-input"  >
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">批号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="wareBatchNumber" id="test8" lay-verify="" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                              <div class="layui-inline">
                                  <label class="layui-form-label">生产日期</label>
                                  <div class="layui-input-inline">
                                      <input type="text" class="layui-input test-item" name = "drManufactureDate" lay-verify="required" lay-reqtext="生产日期是必填项，不能为空！"  id="test9" readonly="readonly" autocomplete="off">
                                  </div>
                              </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">有效期</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input test-item" name="drValidityDate" id="test10" lay-reqtext="有效期是必填项，不能为空！"  lay-verify="required" readonly="readonly"  >
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">生产厂家</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="drFactory" id="test11" lay-verify="required"
                                           lay-reqtext="生产厂家是必填项，不能为空！"     class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">原产地</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="drProducingArea"  id="test12" lay-verify="" placeholder=""
                                                   autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>


                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">token</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="token"  id="token" lay-verify="" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">录入时间</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="wareTime"  id="test14" lay-verify="" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">单据号</label>
                                <div class="layui-input-inline">
                                    <input type="datetime" name="documentNo"  id="test15" lay-verify="" placeholder=""
                                           autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="wareRemarks" id="test13" lay-verify="" placeholder=""
                                                   autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>

                            <div class="layui-inline" style="float:right" ;>
                                <td colspan="6" align="right">
                                    <button type="reset" class="layui-btn layui-btn-danger" id="reset">清空</button>
                                    <button type="submit" class="layui-btn layui-btn-warm" id="LAY-component-form-getval" lay-submit="" lay-filter="demo1">添加</button>
                                </td>
                            </div>

                            <div class="layui-input-block">

                            </div>
                        </div>
                    </form>
                </div>
        </div>
    </div>
</div>
</div>
</body>
</html>

<script>
    $(document).ready(function(){
        layui.use(['form', 'layedit', 'laydate','layer'], function(){
            var form = layui.form;
            var layer = layui.layer;
            var layedit = layui.layedit;
            var laydate = layui.laydate;


            lay('.test-item').each(function(){
                laydate.render({
                    elem: this
                    ,format:'yyyy-MM-dd'
                    ,type:'date'
                    ,trigger: 'click'
                });
            });


            layui.$('#warePrice').on('keyup', function(){
                var warePrice=$("#warePrice").val();
                var wareAmount=$("#wareAmount").val();
                var warePriceTotal=wareAmount*warePrice;
                // console.log("warePrice"+warePrice);
                // console.log("wareAmount"+wareAmount);
                // console.log("warePriceTotal"+warePriceTotal);
                $("#warePriceTotal").val(warePriceTotal);
                checkRate(warePrice);
            })

            layui.$('#wareAmount').on('keyup', function(){
                var wareAmount=$("#wareAmount").val();
                // console.log(wareAmount);
                checkRate2(wareAmount);
            })


            //点击添加，发送ajax请求
            form.on('submit(demo1)', function(){
                //生成录入时间
                var date=new Date();
                var year =date.getFullYear();
                var month=date.getMonth()+1;
                var day=date.getDate()+1;
                var warTime=year+"-"+month+"-"+day;
                // console.log("录入时间："+warTime)

                // 生成单据号
                var num="RK";
                var warNum=num+year+month+day;
                for (var i=0;i<6;i++){
                     warNum+=Math.floor(Math.random()*10);
                }
                var token = sessionStorage.getItem("token");
                // console.log("单据号："+warNum);
                console.log("token="+token);
                //将生成的录入时间,单据号 赋值给表单 录入时间,单据号字段
                form.val('example', {
                    "wareTime": warTime
                    ,"documentNo":warNum
                    ,"token":token
                });
               //获取表单的值
                var data = form.val('example');
                // alert(JSON.stringify(data));
                $.ajax({
                    url:"/JT90/warehouse/add",
                    data:data,
                    dataType:"json",
                    type:"post",
                    success:function(Data){
                        if(Data.success){
                            alert(Data.message);
                            location.reload();
                           // layer.msg(Data.message);
                           // console.log("入库单据添加成功：++++++"+Data.message)
                        }else{
                            layer.msg(Data.message);
                        }
                    },
                    error:function(){ alert("程序出错！");}
                });
                return false;
            })



            //点击清空，清除页面数据
            $("#reset").trigger("click");
        });

        function checkRate(warePrice) {
            var re = /^[0-9]+.?[0-9]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
            if (!re.test(warePrice)) {
                layer.msg("单价必须为数字");
            }
        }
        function checkRate2(wareAmount) {
            var re = /^[0-9]+.?[0-9]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
            if (!re.test(wareAmount)) {
                layer.msg("数量必须为数字");
            }
        }
    })
</script>


